﻿@page "/checkout"
@inject OrderState OrderState

<div class="main">
    <EditForm Model="@OrderState.Order.DeliveryAddress">
        <div class="checkout-cols">
            <div class="checkout-order-details">
                <h4>Review order</h4>
                <OrderReview Order="@OrderState.Order" />
            </div>

            <div class="checkout-delivery-address">
                <h4>Deliver to...</h4>
                <AddressEditor Address="@OrderState.Order.DeliveryAddress" />
            </div>
        </div>

        <button type="submit" class="checkout-button btn btn-warning">
            Place order
        </button>

        <DataAnnotationsValidator />
    </EditForm>
</div>

@functions {
    protected override void OnInitialized()
    {
        // Try to recover any temporary saved order
        OrderState.ReplaceOrder(new Order());
    }
}
